package com.playmodule.vr.utils;

import android.net.Uri;

import java.io.File;
import java.io.FileInputStream;

public class FileHelper
{
  public static String[] IMAGE_EXT = { "jpg", "jpeg", "jpe", "gif", "png", "bmp", "webp" };
  public static String[] VIDEO_EXT = { "3gp", "avi", "divx", "f4v", "flv", "mkv", "mp4", "mpeg", "mpg", "mov", "vob", "wmv", "webm", "xvid" };
  
  public static File getSideCarFile(Uri paramUri, String paramString)
  {
    String path = paramUri.getPath();
    if((path == null) || (!path.contains("."))) {
      return null;
    }
    File file = new File(path);
    if(!file.exists()) {
      return null;
    }
    return file;
  }
  
  public static boolean hasStreamingScheme(String paramString)
  {
    return (paramString.startsWith("http://")) || (paramString.startsWith("https://")) || (paramString.startsWith("rtsp://")) || (paramString.startsWith("rtp://"));
  }
  
  public static boolean isGoogleDriveDocument(Uri paramUri)
  {
    return "com.google.android.apps.docs.storage".equals(paramUri.getAuthority());
  }
  
  public static boolean isImage(String paramString)
  {
    for (int i = 0;; i++)
    {
      if (i >= IMAGE_EXT.length) {
        return false;
      }
      if (paramString.toLowerCase().endsWith("." + IMAGE_EXT[i])) {
        return true;
      }
    }
  }
  
  public static boolean isPlaylist(String paramString)
  {

      if(paramString.toLowerCase().endsWith("." + "m3u")){
        return true;
    }
    return false;
  }
  
  public static boolean isVideo(String paramString)
  {
    for (int i = 0;i < VIDEO_EXT.length; i++)
    {
      if (paramString.toLowerCase().endsWith("." + VIDEO_EXT[i])) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isYoutubeUrl(String paramString)
  {
    return (paramString.startsWith("http://www.youtube.com")) || (paramString.startsWith("http://youtube.com")) || (paramString.startsWith("http://m.youtube.com")) || (paramString.startsWith("http://www.youtu.be")) || (paramString.startsWith("http://youtu.be")) || (paramString.startsWith("http://m.youtu.be")) || (paramString.startsWith("https://www.youtube.com")) || (paramString.startsWith("https://youtube.com")) || (paramString.startsWith("https://m.youtube.com")) || (paramString.startsWith("https://www.youtu.be")) || (paramString.startsWith("https://youtu.be")) || (paramString.startsWith("https://m.youtu.be"));
  }
  
  public static String readFile(File paramFile)
  {
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(paramFile);
      byte[] arrayOfByte = new byte[localFileInputStream.available()];
      localFileInputStream.read(arrayOfByte);
      localFileInputStream.close();
      String str = new String(arrayOfByte, "UTF-8");
      return str;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }
}
